package log

import (
	"io/ioutil"
	"log"
	"strings"
)

// 日志文件夹
var receiveDirPathBase = "./receive_logs/"
var pushDirPathBase = "./push_logs/"

func fileList(dirPath, prefix string) []string {

	files, err := ioutil.ReadDir(dirPath)
	if err != nil {
		log.Fatal(err)
	}

	fileNames := []string{}
	for _, file := range files {
		if strings.HasPrefix(file.Name(), prefix) {
			file := strings.Replace(file.Name(), prefix, "", -1)
			fileNames = append(fileNames, file)
		}
	}

	reverseArray(fileNames)

	return fileNames
}

// 数组翻转
func reverseArray(arr []string) {
	length := len(arr)
	for i := 0; i < length/2; i++ {
		arr[i], arr[length-i-1] = arr[length-i-1], arr[i]
	}
}
